<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>支付设置</title>
    {template 'stourtravel/public/public_min_js'}
    {Common::getCss('style.css,base.css,base_new.css')}
    {Common::getScript('jquery.upload.js')}
</head>
<body>
<table class="content-tab">
    <tr>
        <td valign="top" class="content-rt-td">
            <form id="frm">
                <ul class="info-item-block">
                    {if $settlement_id==1}
                    <li>
                        <span class="item-hd">加价方式：</span>
                        <div class="item-bd">
                            <label class="check-label mr-10"><input type="radio" name="settlement_key" checked="checked" value="1">百分比</label>
                            <label class="check-label ml-10"><input type="radio" name="settlement_key" value="2">固定金额</label>
                        </div>
                    </li>
                    <li>
                        <span class="item-hd company-ico">百分比：</span>
                        <div class="item-bd">
                            <span class="item-text c-999">在供应价基础上加价</span>
                            <input type="text" name="settlement_val" onkeyup="verifyVal($(this))" class="input-text w80">
                            <span class="item-text c-999 ico-company">%</span>
                        </div>
                    </li>
                    {else}
                    <li>
                        <span class="item-hd">抽佣方式：</span>
                        <div class="item-bd">
                            <label class="check-label mr-10"><input type="radio" name="settlement_key" checked="checked" value="1">百分比</label>
                            <label class="check-label ml-10"><input type="radio" name="settlement_key" value="2">固定金额</label>
                        </div>
                    </li>
                    <li>
                        <span class="item-hd company-ico">百分比：</span>
                        <div class="item-bd">
                            <span class="item-text c-999">在销售价基础上抽佣</span>
                            <input type="text" name="settlement_val" onkeyup="verifyVal($(this))" class="input-text w80">
                            <span class="item-text c-999 ico-company">%</span>
                        </div>
                    </li>
                    {/if}
                </ul>
                <div class="clear clearfix mt-20">
                    <a class="btn btn-primary radius size-L ml-115" href="javascript:;" onclick="ajax_save_commission()">保存</a>
                    <input type="hidden" name="type_id" value="{$type_id}">
                    <input type="hidden" name="suit_id" value='{$suit_id}'>
                    <input type="hidden" name="settlement_id" value="{$settlement_id}">
                    <input type="hidden" name="channel_id" value="{$channel_id}">
                </div>
            </form>
        </td>
    </tr>
</table>
<script>
    function ajax_save_commission()
    {
        var settlement_key = $("[name='settlement_key']").val();
        if(!settlement_key){
            ST.Util.showMsg('请填写完整信息!',5,2000);
            return false;
        }
        $.ajaxform({
            url      : SITEURL+"commission/ajax_save_commission",
            method   : "POST",
            form     : "#frm",
            dataType : 'json',
            success  :  function(data)
            {
                if(data.status)
                {
                    ST.Util.showMsg('保存成功!','4',2000);
                    ST.Util.responseDialog(data,true);
                }
                else
                {
                    ST.Util.showMsg(data.msg,'5',2000);
                }
            }
        });
    }
    function verifyVal(obj)
    {
        var settlement_key = $("[name='settlement_key']:checked").val();
        var val = obj.val();
        if(settlement_key==1){
            val = val.replace(/\D/g,'');
            if(val>100)
                val = 100;
            if(val<0)
                val = 0;
        }else{
            val = val.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')
        }
        obj.val(val);
    }
    $(function (){
        $("[name='settlement_key']").on('click',function(){
            var val = $(this).val();
            if(val==1){
                $('.company-ico').html('百分比：');
                $('.ico-company').html('%');
            }else{
                $('.company-ico').html('固定金额：');
                $('.ico-company').html('元');
            }
        })
    })
</script>
</body>
</html>
